<template>
  <!-- 直采商城 -->
  <div class="zhicai-wrap">
    <div class="header">
      <p class="title">直采商城</p>
    </div>
    <div class="display">
      <div class="item">
        <span class="icon icon1"></span>
        <p class="val">
          <count-to
            class="val"
            :startVal="0"
            :endVal="amount"
            :duration="1000"
            :decimals="2"
          ></count-to>
        </p>
        <p class="key">累计交易额(万元)</p>
      </div>
      <div class="item item-content">
        <span class="icon icon2"></span>
        <p class="val">
          <count-to
            class="val"
            :startVal="0"
            :endVal="order"
            :duration="1000"
          ></count-to>
        </p>
        <p class="key">总订单数(笔)</p>
      </div>
      <div class="item">
        <span class="icon icon3"></span>
        <p class="val">
          <count-to
            class="val"
            :startVal="0"
            :endVal="goods"
            :duration="1000"
          ></count-to>
        </p>
        <p class="key">商品总数(个)</p>
      </div>
    </div>
    <div class="chart-wrap">
      <Echart
        id="zhicai-chart"
        :options="option"
        height="206px"
        width="542px"
      />
    </div>
  </div>
</template>

<script setup>
import { reactive, ref, onMounted } from "vue";
import Echart from "@/components/echart/index.vue";
import CountTo from "@/components/vueCountTo/vue-countTo.vue";
import { ajax } from "@/store/service";
import { dataGroup } from "@/utils";
import opt from "./zhicaiMallOpt";

const amount = ref(0);
const order = ref(0);
const goods = ref(0);
const option = reactive({ ...opt });

const init = async () => {
  const [res] = await ajax.zhicai();
  amount.value = res.amount;
  order.value = res.order;
  goods.value = res.goods;
  const chart = dataGroup(res.chart);
  option.xAxis[0].data = chart.x;
  option.series[0].data = chart.y;
};

onMounted(() => {
  init();
});

</script>

<style scoped lang='scss'>
.zhicai-wrap {
  width: 1114px;
  height: 293px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .header {
    width: 1114px;
    height: 68px;
    background: url("@/assets/longscreen2/直采商城标题.svg");
    box-sizing: border-box;
    padding-top: 30px;
    padding-left: 37px;
    margin-bottom: 19px;
    .title {
      font-size: 22px;
      font-family: JLinXin;
      font-weight: 600;
      line-height: 22px;
      background: #fffde8 linear-gradient(180deg, #e8feff 40%, #00a9ff 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      font-weight: bolder;
    }
  }
  .display {
    width: 542px;
    // height: 206px;
    display: flex;
    padding: 0 25px;
    box-sizing: border-box;
    .item {
      flex: 1;
      padding-top: 25px;
      display: flex;
      flex-direction: column;
      align-items: center;
      .icon {
        width: 92px;
        height: 92px;
        display: block;
        margin: 0 auto;
        margin-bottom: 28px;
        // margin-top: 14px;
      }
      .icon1 {
        background: url("@/assets/longscreen2/icon_累计交易额.png");
      }
      .icon2 {
        background: url("@/assets/longscreen2/icon_商品总数.png");
      }
      .icon3 {
        background: url("@/assets/longscreen2/icon_总订单数.png");
      }
      .val {
        font-size: 26px;
        font-family: D-DIN-PRO-Heavy, D-DIN-PRO;
        font-weight: 800;
        color: #ffffff;
        overflow: hidden;
        white-space: nowrap;
        margin: 0 auto;
        letter-spacing: 1px;
        margin-bottom: 6px;
        .unit {
          font-size: 18px;
          font-family: SourceHanSansCN-Medium, SourceHanSansCN;
          font-weight: 500;
          color: #ffffff;
          line-height: 27px;
          opacity: 0.36;
        }
      }
      .key {
        font-size: 18px;
        font-family: SourceHanSansCN-Medium, SourceHanSansCN;
        font-weight: 500;
        color: #ffffff;
        line-height: 27px;
        opacity: 0.7;
      }
    }
    .item-content {
      margin: 0 10px;
    }
  }
  .chart-wrap {
    width: 542px;
    height: 206px;
    // border: 1px #00a9ff solid;
  }
}
</style>